WooCommerce: Display Advanced Custom Fields @ Single Product |
您所在的位置:网站首页 › product page 17 › WooCommerce: Display Advanced Custom Fields @ Single Product |
WooCommerce: Display Advanced Custom Fields @ Single Product
> Published: Mar 2017 - Revised: Mar 2019
> Blog Category: WooCommerce Tips
> Blog Tags: ACF, Price
> Blog Comments: 64 Comments
Tweet
Join 17,000+ WooWeekly subscribers Advanced Custom Fields plugin is a great way to add custom, advanced fields to the WooCommerce Single Product Page. Many struggle to display such fields on the front-end, so this simple snippet should help you! ![]() You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?" Does this snippet (still) work?Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance! Need Help with WooCommerce?Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug! ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Business Bloomer Founder Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli Category: WooCommerce Tips Tags: ACF, Price 64 thoughts on “WooCommerce: Display Advanced Custom Fields @ Single Product”Hi, I use the below code to display the ACF field at the bottom of the product archive, but it doesn’t work. ReplyI google and find the alternative code, it works well on my site. Hope can help anyone who needs it. Replace the “seoct” only with your ACF field name. add_action( ‘woocommerce_after_shop_loop’, ‘diiamo_display_acf_field_under_product’, 11); function diiamo_display_acf_field_under_product() { $term = get_queried_object(); $seo_content = get_field(‘seoct’, $term); if( !empty($seo_content) ) { echo ” . $seo_content . ”; } } Replythank you thats right in medilink theme ReplyCool ReplyHi and thank you very much for that snippet. It works fine fo me but i have a problem with title. If none of the fields have value it is not showing up but the title does. How i can hide the title “SPECIFICATIONS” if one of the fileds have value ? add_action( 'woocommerce_product_meta_end', 'bbloomer_display_acf_field_under_images', 40 ); function bbloomer_display_acf_field_under_images() { echo ""; echo 'SPECIFICATIONS'; echo ""; if( get_field('net_weight') ): echo 'Net weight: ' . get_field('net_weight'); echo ""; endif; if( get_field('sealing') ): echo 'Sealing: ' . get_field('sealing'); echo ""; endif; . . . etc .......thanks in advance . Replysorry i mean “if none of the fileds have value”…. ReplyYou’re already checking if those fields exist below, right? Simply add another check on top, to see if one OR the other exist ReplyHi Rodolfo, your blog is really great. I’ve found many interesting posts. I’ve inserted your script in my function.php and it works. But it works only if my custom field is a Editor Wysiwyg field type. But if my custom field is a checkbox? How can I modify your script? I tried to change get_field with the_field but it doesn’t work. Thanks. ReplyHi Fabrizio, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyHow do I show advanced custom field in an existing single product tab? please reply. Thanks ReplyHi Aziz, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyHi there, thanks for sharing this great snippet! I was just wondering if it’s somehow possible to only show the ACF field if it has got a value? I reckon that would be really useful… Also, is it easy to change to code to show a standard custom field? Many thanks for your help! ReplyHi Jonas, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyHello, is there a way to get these fields to display after the product meta information instead of after the photo? Using this PHP line to get my other fields to display, and they are working properly but I would like my ACF to appear under them… ReplyHello Whitney, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyHi, thanks so much for this! Is there a way I can display custom taxonomies too? ReplyAlso, is there any way I can wrap each custom field in a div? ReplyHi Kelly, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyHello Rodolfo, it still working fine. I just couldn’t handle show up prepend and append values on frontend. Could you please guide an example for us? Thank you so much. ReplyHi Ahmet, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyHi, Rodolfo Thanks for the snippet! Do you happen to have one for displaying custom fields for a variable product? I have custom field for the variations, but can’t get them to display on the product page. thnx in advance! ReplyI don’t, sorry ReplyHi, It would be great if you could do a tutorial for adding ACF fields to the checkout page too. ReplyI’ll think about it. Thank you ReplyWorks great on Aug 6, 2019. Thank you! ReplyExcellent! ReplyHi Rodolfo, thanks for this tutorial 🙂 Can You explain how to display field in product only if product is marked as “featured”? ReplyHello Juraj, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ReplyNot working. THis is what i added to the functions/php in my snippet plugin. Please advise. /** * @snippet Display Advanced Custom Fields @ Single Product - WooCommerce * @how-to Get CustomizeWoo.com FREE * @sourcecode https://businessbloomer.com/?p=22015 * @author Rodolfo Melogli * @testedwith WooCommerce 2.5.2 */ add_action( 'woocommerce_product_thumbnails', 'bbloomer_display_acf_field_under_images', 30 ); function bbloomer_display_acf_field_under_images() { echo 'Specs: ' . get_field('wattage'); echo 'Specs: ' . get_field('voltage'); echo 'Specs: ' . get_field('flange_size'); echo 'Specs: ' . get_field('immersion_length'); echo 'Specs: ' . get_field('includes'); // Note: 'trade' is the slug of the ACF } ReplyNot sure Amy, is ACF set up properly? Works for me. ReplyIt still works, thanks so much, I spent hours trying to solve this! 🙂 ReplyFantastic! ReplyHi there, I am running Woocomerce and WC Vendors, and have managed to create a custom field “ISBN Number” on my Product Page to enter a ISBN Number. I want, no need it to show on an individual product page and be searchable. I have attempted the code on this page and on https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/ to add the visual hook, but still can’t see it after adding to the functions.php Unless it is not obvious, I am am not a dev haha! please help! ReplyHello there, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R ReplyHow can i change the font of the field that is displayed? ReplyAndrea, thanks for your comment! You’ll need custom CSS for that 🙂 ReplyI can output single field without a problem but can someone tell me how my code should look if I have these repeater fields which are arrays. Training Price:R Excl VAT Course Duration: Days CPD Points: Points Course Dates (You must select a date listed here to enable form submit) Johannesburg |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |